package com.nbsaas.boot.project.controller;

import com.nbsaas.boot.project.api.apis.ProjectCatalogApi;
import com.nbsaas.boot.project.api.domain.request.ProjectCatalogRequest;
import com.nbsaas.boot.project.api.domain.request.ProjectCatalogSearch;
import com.nbsaas.boot.project.api.domain.response.ProjectCatalogResponse;
import com.nbsaas.boot.project.api.domain.simple.ProjectCatalogSimple;
import com.nbsaas.boot.project.ext.apis.ProjectCatalogExtApi;
import com.nbsaas.boot.rest.annotations.*;
import com.nbsaas.boot.rest.response.ListResponse;
import com.nbsaas.boot.rest.response.PageResponse;
import com.nbsaas.boot.rest.response.ResponseObject;
import jakarta.annotation.Resource;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 项目分类控制器
 */
@RequiresAuthentication
@RestController
@RequestMapping("/projectCatalog")
public class ProjectCatalogController {


    @Resource
    private ProjectCatalogApi projectCatalogApi;

    @Resource
    private ProjectCatalogExtApi projectCatalogExtApi;

    /**
     * 搜索数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("projectCatalog:search")
    @PostMapping("/search")
    public PageResponse<ProjectCatalogSimple> search(@RequestBody ProjectCatalogSearch request) {
        return projectCatalogApi.search(request);
    }

    /**
     * 列表数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("projectCatalog:list")
    @PostMapping("/list")
    public ListResponse<ProjectCatalogSimple> list(@RequestBody ProjectCatalogSearch request) {
        return projectCatalogApi.list(request);
    }

    /**
     * 添加数据
     *
     * @param request
     * @return
     */
    @RequiresPermissions("projectCatalog:create")
    @CreateData
    @PostMapping("/create")
    public ResponseObject<ProjectCatalogResponse> create(@RequestBody @Validated(AddOperator.class) ProjectCatalogRequest request) {
        return projectCatalogApi.create(request);
    }

    /**
     * 修改数据
     *
     * @param request
     * @return
     */
    @RequiresPermissions("projectCatalog:update")
    @UpdateData
    @PostMapping("/update")
    public ResponseObject<ProjectCatalogResponse> update(@RequestBody @Validated(UpdateOperator.class) ProjectCatalogRequest request) {
        return projectCatalogApi.update(request);
    }

    /**
     * 删除数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("projectCatalog:delete")
    @PostMapping("/delete")
    public ResponseObject<?> delete(@RequestBody @Validated(DeleteOperator.class) ProjectCatalogRequest request) {
        return projectCatalogExtApi.deleteExt(request);
    }

    /**
     * 查看数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("projectCatalog:view")
    @PostMapping("/view")
    public ResponseObject<ProjectCatalogResponse> view(@RequestBody @Validated(ViewOperator.class) ProjectCatalogRequest request) {
        return projectCatalogApi.view(request);
    }
}